package com.javasm.service.goodsService.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javasm.common.page.PageResult;
import com.javasm.domin.criteria.goodsCriteria.GdProductCriteria;
import com.javasm.domin.criteria.goodsCriteria.GoodsCriteria;
import com.javasm.domin.entity.goodsEntity.GdProduct;
import com.javasm.domin.vo.goodsVo.GdProductVo;
import com.javasm.mapper.goodsMapper.GdProductMapper;
import com.javasm.service.goodsService.GdProductService;
import com.javasm.transfer.goodsTransfer.GdProductTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author Administrator
* @description 针对表【gd_product】的数据库操作Service实现
* @createDate 2021-11-22 15:00:27
*/
@Service
@Transactional
@RequiredArgsConstructor
public class GdProductServiceImpl extends ServiceImpl<GdProductMapper, GdProduct>
implements GdProductService {


    @Autowired
    private GdProductMapper gdProductMapper;

    @Autowired
    private GdProductTransfer gdProductTransfer;


    @Override
    public PageResult<GdProductVo> searchPage(GdProductCriteria gdProductCriteria) {
        Integer brandId = gdProductCriteria.getBrandId();
        Integer colourId = gdProductCriteria.getColourId();
        Integer typeId = gdProductCriteria.getTypeId();
        String modelId = gdProductCriteria.getModelId();
        Integer goodsId = gdProductCriteria.getGoodsId();
        LambdaQueryWrapper<GdProduct> lambda = new QueryWrapper<GdProduct>().lambda();

        if (!StringUtils.isEmpty(modelId)){
            lambda.like(GdProduct::getModelId,modelId);
        }
        if (!StringUtils.isEmpty(goodsId)){
            lambda.like(GdProduct::getGoodsId,goodsId);
        }
        if (!StringUtils.isEmpty(brandId)){
            lambda.eq(GdProduct::getBrandId,brandId);
        }
        if (!StringUtils.isEmpty(colourId)){
            lambda.eq(GdProduct::getColourId,colourId);
        }
        if (!StringUtils.isEmpty(typeId)){
            lambda.eq(GdProduct::getTypeId,typeId);
        }

        PageHelper.startPage(gdProductCriteria.getCurrentPage(),gdProductCriteria.getPageSize());

        List<GdProduct> gdProductList = gdProductMapper.selectList(lambda);

        PageInfo<GdProduct> gdProductPageInfo = new PageInfo<>(gdProductList);

        long total = gdProductPageInfo.getTotal();

        List<GdProductVo> set = gdProductTransfer.set(gdProductList);

        return new PageResult<GdProductVo>(total,set);
    }
}
